home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1873 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  4.1 KB

  1. Path: 129.132.1.13!neeri
  2. From: neeri@iis.ee.ethz.ch (Matthias Neeracher)
  3. Newsgroups: comp.lang.misc,comp.lang.perl.misc,comp.lang.tcl,comp.lang.c,comp.lang.java
  4. Subject: Re: Relative Speed of Perl vs. Tcl vs. C
  5. Followup-To: comp.lang.misc
  6. Date: 17 Jan 1996 10:03:20 GMT
  7. Organization: Integrated Systems Laboratory, ETH, Zurich
  8. Message-ID: <NEERI.96Jan17110320@yggdrasil.ethz.ch>
  9. References: <4dhuoj$cbe@shellx.best.com>
  10. NNTP-Posting-Host: yggdrasil.ethz.ch
  11. In-reply-to: yogi@shellx.best.com's message of 16 Jan 1996 20:42:59 -0800
  12.  
  13. [Followups redirected to comp.lang.misc only]
  14. In article <4dhuoj$cbe@shellx.best.com> yogi@shellx.best.com (Yogi) writes:
  15. > I don't want to start a religeous war, and YES, I did read the FAQ's,
  16. > and did not find any info on relative speed of comparing C vs Perl vs Tcl
  17. > vs Java in a very general sort of fashion.
  18.  
  19. There is a recent posting in comp.lang.java attempting such a comparison.
  20.  
  21. > I'm very interested in the uses of Tcl and Perl, with regard to Tk and 
  22. > other GUI toolkits (what other's are there?)
  23.  
  24. By now, almost everybody working with the two languages, seems to be committed
  25. to Tk.
  26.  
  27. > Can't seem to find any info on statements I have read that seem to conflict:
  28.  
  29. > Somewhere I have read that Perl coded grep runs as fast or faster than C
  30. > coded grep in Unix. (Larry Wall wrote this, correct me if I'm wrong.)
  31.  
  32. Possible. grep is almost built into perl.
  33.  
  34. > And in a CGI-web book I read that Perl is an interpreted language that runs
  35. > 10 times slower than C.
  36.  
  37. According to Tom Christiansen, a typical factor is on the order of "e", i.e.,
  38. 2.7.
  39.  
  40. > But Perl is compiled, right?
  41.  
  42. Precompiled, I'd say. I wouldn't call a language "compiled" unless there exists
  43. a mechanism for storing compiled programs in non-source form. A compiler is in
  44. development, though. 
  45.  
  46. > So how is that different than say, the Tcl interpreter?
  47.  
  48. Perl and Tcl are almost on the two extreme sides of interpreter
  49. technology. Perl precompiles into an internal parse tree, while Tcl is pure
  50. sring substitution. As an example, compare:
  51.  
  52. Perl:                                Tcl:
  53. for ($i = 0; $i<100; $i++) {         for {set i 0} {$i<100} {incr i} {
  54.  for ($j = 0; $j=100; $j++) {         for {set j 0} {$j<100} {incr j} {
  55.   for ($k = 0; $k<100; $k++) {         for {set k 0} {$k<100} {incr k} {
  56.    print $i, " ", $j, " ", $k, "\n";    puts "$i $j $k\n";
  57.   }                                    }
  58.  }                                    }
  59. }                                    }
  60.  
  61. Syntactically, the two examples are very similar. But while the Perl lexical
  62. analyzer makes a single pass over the text of the innermost loop, the Tcl
  63. lexical analyzer makes MORE THAN A MILLION passes over the text.
  64.  
  65. This does not mean, though, that Tcl is bad. In fact, I find it more than fast
  66. enough for the work I do in it.
  67.  
  68. > So what's the real answer, or are both statements true somehow? I know that
  69. > Perl can run faster or slower depending on how you code it, (C too) and so I
  70. > guess you would have to find the fastest C code for a particular function and
  71. > similar fastest Perl code (or Tcl) and compare THOSE programs to get a
  72. > definative answer.
  73.  
  74. One important point to make here is that for text processing problems, it is
  75. much easier writing a close to optimal Perl solution that a close to optimal
  76. C solution and therefore, the Perl solution is often faster although it is
  77. easily proven that a C solution that is at leats as fats must exist.
  78.  
  79. > And then, what about the speed of Java in comparison to the other 3?
  80.  
  81. Java proponents will tell you that this doesn't matter because Java has "won"
  82. already. Java detractors will tell you that your question is pointless as there
  83. are not a single release quality implementation of Java in existence as of now.
  84.  
  85. Matthias
  86.  
  87. -----
  88. Matthias Neeracher <neeri@iis.ee.ethz.ch> http://err.ethz.ch/members/neeri.html
  89.   "We have built a lot of security directly into Java to make it virus-proof.
  90.    And people's concerns about security on the Net tend to be based on age.
  91.    You talk to people in their twenties and they are much less concerned about
  92.    it than older generations. Pretty soon it won't worry them at all."'
  93.                                 -- Scott McNealy, _Sunday Times_ 19Nov95
  94.  
  95.  
  96.